import axios from "axios"

const url = process.env.NODE_ENV === "production" ? "/" : "/api";
const http = axios.create({
  baseURL: url,
  timeout: 30000
})

http.interceptors.request.use( config =>{
  // 时间戳, 解决IE缓存的问题
  config.headers['bwTicket'] = 'fe4004c499724f13a7424e319038f006';
  config.headers['timestamp'] = '1637654780955';
  config.headers['nonce'] = '414293';
  config.headers['signature'] = '3950d7329274a42559dc7596d8e2d6a8';
  if (config.method === 'get') {
    config.params = {
      t: Date.parse(String(new Date().getTime())) / 1000,
      ...config.params
    }
  }
  return config
  },
  error => {
    Promise.reject(error);
  }

)

export default http